require("Cocos2d")
require("src/GameConfig")
require("src/scene/SceneMgr")

function __G__TRACKBACK__(msg)
  local cclog = function(...)
    print(string.format(...))
  end
  cclog("----------------------------------------")
  cclog("LUA ERROR: " .. tostring(msg) .. "\n")
  cclog(debug.traceback())
  cclog("----------------------------------------")
  return msg
end
local main = function()
  collectgarbage("collect")
  collectgarbage("setpause", 100)
  collectgarbage("setstepmul", 5000)
  cc.FileUtils:destroyInstance()
  local fileUtils = cc.FileUtils:getInstance()
  local path = cc.FileUtils:getInstance():getWritablePath() 
  local searchPaths = fileUtils:getSearchPaths()
  table.insert(searchPaths, 1, path)
  table.insert(searchPaths, 1, path .. "/src")
  table.insert(searchPaths, 1, path .. "/res")
  table.insert(searchPaths, 1, path .. "/res/image")
  table.insert(searchPaths, 1, path .. "/res/image/ui")
  table.insert(searchPaths, "src")
  table.insert(searchPaths, "res")
  table.insert(searchPaths, "res/image")
  table.insert(searchPaths, "res/image/ui/")
  fileUtils:setSearchPaths(searchPaths)
  SceneMgr:switchToLoading()
 
end
local status, msg = xpcall(main, __G__TRACKBACK__)
if not status then
  error(msg)
end
